package com.gyx.metaldesigndemo.coordinator;

import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.gyx.metaldesigndemo.R;

public class BehaviorTopTestActivity extends AppCompatActivity {
    private Toolbar toolbar;
    private NestedScrollView nestedScrollView;
    private ImageView topIv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_behavior_top_test);
        toolbar= (Toolbar) findViewById(R.id.toolbar);
        nestedScrollView= (NestedScrollView) findViewById(R.id.nestedSv);
        topIv= (ImageView) findViewById(R.id.topTv);
        initToolBar();
        initViews();
    }

    private void initViews() {
        topIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                nestedScrollView.scrollTo(0,0);
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_toolbar_activity,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.menu1:
                Toast.makeText(this,"menu1",Toast.LENGTH_SHORT).show();
                break;
            case R.id.menu2:
                Toast.makeText(this,"menu2",Toast.LENGTH_SHORT).show();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    private void initToolBar(){
        toolbar.setTitle("你好");
        toolbar.setLogo(R.mipmap.ic_launcher);
        toolbar.setSubtitle("我好");

        toolbar.setNavigationIcon(R.mipmap.ic_launcher);

        setSupportActionBar(toolbar);


        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }
}
